<!--
 * @Description: 
 * @Author: william
 * @Date: 2025-07-22 10:45:46
 * @LastEditors: william
 * @LastEditTime: 2025-08-22 13:34:03
-->
<template>
  <view class="content" style="padding-top: 58rpx">
    <button @click="getDeviceSize">获取设备剩余空间</button>
    <view>{{ JSON.stringify(systemSize) }}</view>
    <input
      type="text"
      v-model="msg"
      style="height: 50px"
      placeholder="请输入需要写入的日志内容"
    />
    <button @click="writeBtn">写入</button>
    <button @click="getListBtn">读取文件列表</button>
    <button @click="delBtn">删除第一个文件</button>
    <button @click="delAllBtn">删除所有文件</button>
    <button @click="delOverNumBtn">删除超过2个的文件</button>
    <view>日志列表：(点击列表可查看对应日志内容)</view>
    <view v-for="(item, index) in log_list" :key="index" @click="readLog(item)">
      <view>文件名称:{{ item.name }}</view>
      <view>文件路径:{{ item.filePath }}</view>
      <view>文件大小:{{ item.size }}</view>
      <br />
    </view>
    <view>日志内容：</view>
    <view style="max-height: 50vh; overflow-y: auto">
      <view v-for="(item, index) in log_data_list" :key="index">
        {{ item }}
      </view>
    </view>
  </view>
</template>

<script>
import LogCat from '@/js_sdk/AppLog/AppLog.js'

export default {
  data() {
    return {
      msg: 'log123456789abc啊啊啊',
      log_list: [],
      log_data_list: [],
      systemSize: {}
    }
  },
  onLoad() {
    LogCat.init()
  },
  methods: {
    getDeviceSize() {
      const systemSize = LogCat.getSystemStorage()
      this.systemSize = systemSize
      console.log('systemSize', systemSize)
    },
    writeBtn() {
      if (!this.msg) {
        // uni.showToast({
        //   title: '请输入需要写入的内容'
        // })
        return
      }
      LogCat.writeLog('info', this.msg)
      this.getListBtn()
    },
    getListBtn() {
      this.log_list = LogCat.getLogFileList()
      console.log('this.log_list', this.log_list)
    },
    readLog(item) {
      this.log_data_list = LogCat.readLog(item.filePath)
    },
    delBtn() {
      LogCat.removeLogFile(this.log_list[0].filePath)
      this.$nextTick(() => {
        this.getListBtn()
        // this.log_data_list = []
      })
    },
    delAllBtn() {
      LogCat.removeAllLogFile()
      this.$nextTick(() => {
        this.getListBtn()
        // this.log_data_list = []
      })
    },
    delOverNumBtn() {
      LogCat.deleteOldLogFiles(2)
    }
  }
}
</script>
